package com.construction.api.domain.model.result;

import com.construction.api.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author dybin
 * @Date: 2021/7/1 23:39
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class BaseResult {

    protected Integer code;
    protected String msg;

    public static BaseResult of(Integer code, String msg) {
        return new BaseResult(code, msg);
    }

    public static BaseResult of(ResultEnum resultEnum) {
        return of(resultEnum.getCode(), resultEnum.getMsg());
    }

    public static BaseResult success() {
        return BaseResult.of(ResultEnum.SUCCESS);
    }

    public static BaseResult businessError() {
        return BaseResult.of(ResultEnum.BUSINESS_UNUSUAL);
    }

    public static BaseResult businessError(String msg) {
        return BaseResult.of(ResultEnum.BUSINESS_UNUSUAL.getCode(), ResultEnum.BUSINESS_UNUSUAL.getMsg() + ": " + msg);
    }

    public static BaseResult error(ResultEnum resultEnum) {
        return BaseResult.of(resultEnum);
    }

    public static BaseResult error(ResultEnum resultEnum, String msg) {
        return BaseResult.of(resultEnum.getCode(), resultEnum.getMsg() + ": " + msg);
    }
}
